package com.shimh.cmpp.controller;

import com.shimh.cmpp.util.MsgContainer;
import org.apache.log4j.Logger;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * @ClassName: msgController
 * @Description: TODO
 * @Author: shimh
 * @Date: 2022/8/29
 **/

@RestController
@RequestMapping(value = "/service")
public class MsgController {

    private static Logger LOGGER = Logger.getLogger(MsgController.class);

    @RequestMapping(value = "/send", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
    public Map<String, Object> sendSms(@RequestBody Map<String, String> param) {
        String msg = param.get("msg");
        String tel = param.get("tel");
        Map<String, Object> map = new HashMap<String, Object>();
        try {
            // 建立连接
            MsgContainer.sendMsg(msg, tel);
            map.put("result", true);
            LOGGER.info("[TEL]" + tel + ">>>短信发送成功");
            LOGGER.info("[MSG]" + msg);
            return map;
        } catch (Exception e) {
            LOGGER.error("短信发送失败:", e);
            map.put("result", false);
            return map;
        }
    }

}
